package com.bdzl.credit.controller;

import com.bdzl.credit.service.UserBlackService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.UserBlackDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import com.bdzl.pub.vo.loan.UserBlackVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 客户黑名单表：主要用于记录客户黑名单信息。
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 14:00:09
 */

@Controller
@RequestMapping("/bdzl/userBlack")
public class UserBlackController extends BaseController {
	@Autowired
	private UserBlackService userBlackService;

	@GetMapping()
	String UserBlack(){
	    return "bdzl/userBlack/userBlack";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<UserBlackVO> userBlackList = userBlackService.UserBlackVOList(query);
		int total = userBlackService.count(query);
		PageUtils pageUtils = new PageUtils(userBlackList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/userBlack/add";
	}

	@PostMapping("/edit")
	@ResponseBody
	UserBlackDO edit(@RequestBody UserBlackDO userBlack){
		userBlack = userBlackService.get(userBlack.getBlackId());
	    return userBlack;
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody UserBlackDO userBlack){
		if(userBlackService.save(userBlack)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(@RequestBody UserBlackDO userBlack){
		userBlackService.update(userBlack);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove(@RequestBody UserBlackDO userBlack){
		if(userBlackService.remove(userBlack.getBlackId())>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] blackIds){
		userBlackService.batchRemove(blackIds);
		return R.ok();
	}

}
